import java.awt.Image
import java.awt.AWTException
import java.awt.MenuItem
import java.awt.PopupMenu
import java.awt.SystemTray
import java.awt.Toolkit
import java.awt.TrayIcon

def trayIcon = null

def exit = { e ->
  println "Exiting ..."
  System.exit(0)
}

def showMessage = { e ->
  trayIcon.displayMessage("Action Event",
                        "An Action Event Has Been Peformed!",
                        TrayIcon.MessageType.INFO)
}

if (SystemTray.isSupported()) {
  def tray = SystemTray.getSystemTray()

  def image = Toolkit.getDefaultToolkit().
                        getImage("duke16.gif")

  def popup = new PopupMenu()
  popup.add(new MenuItem(label:"Exit", actionPerformed:exit))

  trayIcon = new TrayIcon(image:image, tooltip:"Tray Demo",
                          popup:popup, imageAutoSize:true,
                          actionPerformed:showMessage)
  try {
    tray.add(trayIcon)
  } catch (AWTException e) {
    println e
  }
} else {
  prinltn "System Tray not supported"
}

